//
//  NSURL+iceNavigator.m
//  ICENavigator
//
//  Created by wujianrong on 2017/12/19.
//  Copyright © 2017年 Wanda. All rights reserved.
//

#import "NSURL+iceNavigator.h"

@implementation NSURL(iceNavigator)
- (NSDictionary *)iceNavigatorParseQuery {
    NSString *query = [self query];
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithCapacity:6];
    NSArray *pairs = [query componentsSeparatedByString:@"&"];
    
    for (NSString *pair in pairs) {
        NSArray *elements = [pair componentsSeparatedByString:@"="];
        
        if ([elements count] <= 1) {
            continue;
        }
        
        NSString *key = [[elements objectAtIndex:0] stringByRemovingPercentEncoding];
        NSString *val = [[elements objectAtIndex:1] stringByRemovingPercentEncoding];
        
        [dict setObject:val forKey:key];
    }
    return dict;
}

@end
